﻿// Decompiled with JetBrains decompiler
// Type: System.Web.Razor.Parser.MarkupCollapser
// Assembly: System.Web.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
// MVID: 682513D6-F37E-48AC-9909-F3EE103CFF14
// Assembly location: D:\Project\Idea\无人机外网\uav\客户端工程\排查工具\bin\Release\System.Web.Razor.dll

using System.Linq;
using System.Web.Razor.Generator;
using System.Web.Razor.Parser.SyntaxTree;
using System.Web.Razor.Text;

namespace System.Web.Razor.Parser
{
  internal class MarkupCollapser : MarkupRewriter
  {
    public MarkupCollapser(
      Action<SpanBuilder, SourceLocation, string> markupSpanFactory)
      : base(markupSpanFactory)
    {
    }

    protected override bool CanRewrite(Span span) => span.Kind == SpanKind.Markup && span.CodeGenerator is MarkupCodeGenerator;

    protected override SyntaxTreeNode RewriteSpan(BlockBuilder parent, Span span)
    {
      if (!(parent.Children.LastOrDefault<SyntaxTreeNode>() is Span span1) || !this.CanRewrite(span1))
        return (SyntaxTreeNode) span;
      parent.Children.Remove((SyntaxTreeNode) span1);
      SpanBuilder builder = new SpanBuilder();
      this.FillSpan(builder, span1.Start, span1.Content + span.Content);
      return (SyntaxTreeNode) builder.Build();
    }
  }
}
